<?php

	session_start();
	require_once('../inc/fnc.php');
	require_once('../inc/constants.php');

	$invitee = $_GET['email'];
	$cur_username = getName($_SESSION['userId']);
	$cur_email = getEmail($_SESSION['userId']);

	//echo $invitee . " " . $cur_username . " " . $_SESSION['userId'];

	if(invite($invitee, $_SESSION['userId'])) {
		$subject = "You are invited by {$cur_username} to join Next Twist";								// subject
					
		$message = $emailTop; 															// message
		$message .=	"<p>You have been invited to join <a href='http://nexttwist.com'>Next Twist</a> by your friend <a href='".DOMAIN."/{$cur_username}'>{$cur_username}</a> ({$cur_email})</p>
					 <p>Next Twist is a fun hangout where you can unleash your creative side.</p><br/>
					 <p><a href='http://nexttwist.com'>Accept the Invitation</a></p>";
		$message .=	 $emailBottom;
		
		$headers  = 'MIME-Version: 1.0' . "\r\n";										// To send HTML mail, the Content-type header must be set
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		$headers .= "From: Next Twist Team <".NOREPLY.">" . "\r\n";
		
		if(mail($invitee, $subject, $message, $headers)){ $error['status'] = true; } else { $error['status'] = false; }		// Mail it
	} else {
		$error['status'] = false;
	}

	echo json_encode($error);

?>